package com.spzx.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.product.domain.ProductSpec;
import com.spzx.product.mapper.ProductSpecMapper;
import com.spzx.product.service.ICategoryService;
import com.spzx.product.service.IProductSpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 商品规格Service业务层处理
 */
@Service
@Transactional
public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, ProductSpec>
implements IProductSpecService {
    @Autowired
    ProductSpecMapper productSpecMapper;
    @Autowired
    ICategoryService categoryService;

    /**
     * 查询商品规格列表
     * @param productSpec 商品规格
     * @return getDataTable(list)
     */
    @Override
    public List<ProductSpec> selectProductSpecList(ProductSpec productSpec) {
        return productSpecMapper.selectProductSpecList(productSpec);
    }

    /**
     * 获取商品规格详细信息
     * @param id 商品规格主键
     * @return 商品规格
     */
    @Override
    public ProductSpec selectProductSpecById(Long id) {
        ProductSpec productSpec = productSpecMapper.selectById(id);
        List<Long> idList = categoryService.getAllCategoryIdList(productSpec.getCategoryId());
        productSpec.setCategoryIdList(idList);
        return productSpec;
    }

    /**
     * 根据分类Id获取商品规格列表
     * @param categoryId 分类Id
     * @return 商品规格列表
     */
    @Override
    public List<ProductSpec> selectProductSpecByCategoryId(Long categoryId) {
        return productSpecMapper.selectList(new LambdaQueryWrapper<ProductSpec>()
                .eq(ProductSpec::getCategoryId,categoryId));
    }
}
